package gjbsh.bangong.ds.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gjbsh.bangong.ds.model.单位附加信息;
import gjbsh.bangong.ds.model.地区;
import gjbsh.bangong.ds.service.单位附加信息Service;
import gjbsh.bangong.ds.service.地区Service;
import gjbsh.bangong.utils.PageInfo;
import gjbsh.share.DeptType;
import gjbsh.support.AppGlobalConfig;
import gjbsh.support.BooleanMessage;
import gjbsh.support.JsonResult;
import gjbsh.support.LoginUser;
import gjbsh.support.StringHandle;


/**
 * @author yaolongjun
 * @date   2020年5月15日 上午8:29:01
 */
@RestController
@RequestMapping("dept_fujiaxinxi")
public class 单位附加信息Controller {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	单位附加信息Service ddService;

	@Autowired
	地区Service dd地区Service;

	@Value("${userfilepath}")
	private String userfilepath;


	@RequestMapping("download_muban")
	public void findfile(HttpServletRequest request, 
			HttpServletResponse response) throws IOException {

		ServletOutputStream out = null;
		FileInputStream ips = null;

		try {
			// 获取项目根目录地址,并去除最后斜杠
			if (userfilepath.endsWith("/")) {
				userfilepath = userfilepath.substring(0, userfilepath.length() - 1);
			}

			String mmPath = "";
			String newFileName = "";
			mmPath = "/muban/danwei/danweitongxunxinximuban.xls";
			newFileName = "danweitongxunxinximuban.xls";
			// 获取文件存放的路径
			File file = new File(userfilepath + mmPath);

			if (!file.exists()) {
				// 如果文件不存在就跳出
				return;
			}
			ips = new FileInputStream(file);
			response.setContentType("multipart/form-data");
			// 为文件重新设置名字，采用数据库内存储的文件名称
			response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(newFileName.getBytes("UTF-8"), "ISO8859-1") + "\"");
			out = response.getOutputStream();
			// 读取文件流
			int len = 0;
			byte[] buffer = new byte[1024 * 10];
			while ((len = ips.read(buffer)) != -1) {
				out.write(buffer, 0, len);
			}
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (ips != null) {
					ips.close();
				}
				if (out != null) {
					out.close();
				}
			} catch (IOException e) {
				System.out.println("关闭流出现异常");
				e.printStackTrace();
			}
		}
		return;
	}

	// 读取文件中的数据
	@SuppressWarnings("resource")
	@RequestMapping("get_value")
	public void get_value(
			@RequestParam("fileurl") String ppFileUrl,
			HttpServletRequest request,
			HttpServletResponse response
			){
		try {

			//取出文档存放的根目录，并去除文件最后的斜杠
			if(userfilepath.endsWith("/")){
				userfilepath  = userfilepath.substring(0, userfilepath.length()-1);
			}

			String url = userfilepath+ppFileUrl;
			Workbook book = null;

			File f = new File(url);   
			InputStream in = new FileInputStream(f);   

			String prefix = url.substring(url.lastIndexOf(".")+1);
			if(prefix.equals("xls")) {
				book = new HSSFWorkbook(in);
			}else if(prefix.equals("xlsx")) {
				book = new XSSFWorkbook(in);
			}else {
				//return JsonResult.getErrorResult("请上传xls或xlsx类型的文件！");
				throw new RuntimeException("请上传xls或xlsx类型的文件！");		
			}

			Sheet sheet = book.getSheetAt(0);
			int column= sheet.getRow(0).getPhysicalNumberOfCells();
			int rows = sheet.getPhysicalNumberOfRows();

			List<Map<String,Object>> mmExcelList = new ArrayList<Map<String,Object>>();

			for (int i = 1; i < rows ; i++) { //行
				Map<String,Object> mmMap = new HashMap<String,Object>();
				mmMap.put("单位名称", getCellFormatValue(sheet.getRow(i).getCell(1)));
				mmExcelList.add(mmMap);
			}
			in.close();   		

			// 根据单位名称去查单位信息		
			ddService.exportDanweixinxi(mmExcelList,request,response);

		} catch (Exception e) {
			logger.error("单位附加信息Controller->get_value: "+ e.getMessage());
		}
	}

	private Object getCellFormatValue(Cell cell) {
		Object cellvalue = "";
		if (cell != null) {
			// 判断当前Cell的Type
			switch (cell.getCellType()) {
			case Cell.CELL_TYPE_NUMERIC:// 如果当前Cell的Type为NUMERIC
			case Cell.CELL_TYPE_FORMULA: {
				// 判断当前的cell是否为Date
				if (DateUtil.isCellDateFormatted(cell)) {
					// 如果是Date类型则，转化为Data格式
					// data格式是带时分秒的：2013-7-10 0:00:00
					// cellvalue = cell.getDateCellValue().toLocaleString();
					// data格式是不带带时分秒的：2013-7-10
					Date date = cell.getDateCellValue();
					cellvalue = date;
				} else {// 如果是纯数字
					cell.setCellType(1);
					// 取得当前Cell的数值
					//cellvalue = String.valueOf(cell.getNumericCellValue());
					cellvalue=cell.getStringCellValue();
				}
				break;
			}
			case Cell.CELL_TYPE_STRING:// 如果当前Cell的Type为STRING
				// 取得当前的Cell字符串
				cellvalue = cell.getRichStringCellValue().getString();
				break;
			default:// 默认的Cell值
				cellvalue = "";
			}
		} else {
			cellvalue = "";
		}
		return cellvalue;
	}


	// 博管会开启更新
	@RequestMapping("modify_all_zhuangtai")
	public JsonResult<?> modify_all_zhuangtai(
			@RequestParam("zhuangtai") String ppZhuangtai,
			HttpServletRequest request){
		try {
			// 获得 单位id
			LoginUser loginUser = (LoginUser)request.getAttribute(AppGlobalConfig.REQUEST_LOGINUSER_NAME);
			String ppDeptId = loginUser.getDeptid();

			if(!ppDeptId.equals("1")) {
				return JsonResult.getErrorResult("您没有开启更新单位通讯和账户信息的权限！");
			}

			return ddService.modifyAllZhuangtai(new BigDecimal(ppZhuangtai)) >= 0 ?  JsonResult.getSuccessResult("开启更新成功！") : JsonResult.getErrorResult("开启更新失败！");

		}catch(Exception e) {
			logger.error("单位附加信息Controller->modify_all_zhuangtai: "+ e.getMessage());
			return JsonResult.getErrorResult("开启更新失败");
		}
	}

	// 查找单位附加信息
	@RequestMapping("find_one")
	public JsonResult<?> find_one(@RequestParam("deptid") String ppDeptId){
		try {	

			return JsonResult.getSuccessResult(ddService.findOne(ppDeptId));

		}catch(Exception e) {
			logger.error("单位附加信息Controller->find_one: "+ e.getMessage());
			return JsonResult.getErrorResult("查找单位附加信息失败");
		}
	}


	// 根据单位id查找单位附加信息
	@RequestMapping("find_by_deptid")
	public JsonResult<?> find_by_deptid(@RequestParam("deptid") String ppDeptId){
		try {

			return JsonResult.getSuccessResult(ddService.findByDeptId(ppDeptId));

		}catch(Exception e) {
			logger.error("单位附加信息Controller->find_by_deptid: "+e.getMessage());
			return JsonResult.getErrorResult("查找指定单位附加信息失败");
		}
	}

	// 删除
	@RequestMapping("delete")
	public JsonResult<?> delete(@RequestParam("deptid") String ppDeptId){
		try {

			单位附加信息 mm单位附加信息 = ddService.findOne(ppDeptId);
			if(mm单位附加信息 == null) {
				return JsonResult.getErrorResult("该单位暂未填写相关信息，无需删除！");
			}

			return ddService.delete(ppDeptId) ? JsonResult.getSuccessResult("删除成功！") :
				JsonResult.getErrorResult("删除失败！");

		}catch(Exception e) {
			logger.error("单位附加信息Controller->delete:"+ e.getMessage());
			return JsonResult.getErrorResult("删除指定单位附加信息失败");
		}
	}

	// 根据单位id及其他条件查找本单位及所有下级单位列表
	@RequestMapping("find_deptlist_by_deptid")
	public JsonResult<?> find_deptlist_by_deptid(			
			@RequestParam("shengfenid") String ppShengfenId,
			@RequestParam("danweimingcheng") String ppDanweimingcheng,
			@RequestParam("danweileixing") String ppDanweileixing,
			@RequestParam("shezhannianfen") String ppShezhannianfen,
			@RequestParam("pageindex") int ppPageIndex,
			@RequestParam("pagesize") int ppPageSize,
			HttpServletRequest request){
		try {
			// 获得 单位id
			LoginUser loginUser = (LoginUser)request.getAttribute(AppGlobalConfig.REQUEST_LOGINUSER_NAME);
			String ppDeptId = loginUser.getDeptid();

			// 单位名称
			ppDanweimingcheng = ppDanweimingcheng.trim();
			if(!"".equals(ppDanweimingcheng)) {
				ppDanweimingcheng = "%"+ppDanweimingcheng+"%";
			}

			// 分页查找该条件下的单位列表
			List<Map<String,Object>> mmDeptList = ddService.findDeptListByConditionPaging(ppDeptId,ppShengfenId,ppDanweimingcheng,ppDanweileixing,ppShezhannianfen,ppPageIndex, ppPageSize);

			// 统计该条件下的单位个数
			int mmCount = ddService.CountDeptByCondition(ppDeptId,ppShengfenId,ppDanweimingcheng,ppDanweileixing,ppShezhannianfen);

			PageInfo mmPageInfo = new PageInfo(ppPageIndex, ppPageSize, mmCount);
			Map<String, Object> mmResultMap = new HashMap<String, Object>();
			mmResultMap.put("DeptList", mmDeptList);
			mmResultMap.put("PageInfo", mmPageInfo);

			return JsonResult.getSuccessResult(mmResultMap);
		}catch(Exception e) {
			logger.error("单位附加信息Controller->find_deptlist_by_deptid: "+ e.getMessage());
			return JsonResult.getErrorResult("查找指定单位的下级单位列表失败");
		}
	}


	// 根据条件导出查询结果
	@RequestMapping("daochuchaxunjieguo")
	public void daochuchaxunjieguo(
			@RequestParam("shengfenid") String ppShengfenId,
			@RequestParam("danweimingcheng") String ppDanweimingcheng,
			@RequestParam("danweileixing") String ppDanweileixing,
			@RequestParam("shezhannianfen") String ppShezhannianfen,

			HttpServletRequest request,
			HttpServletResponse response){
		try {
			// 获得 单位id
			LoginUser loginUser = (LoginUser)request.getAttribute(AppGlobalConfig.REQUEST_LOGINUSER_NAME);
			String ppDeptId = loginUser.getDeptid();

			ppDanweimingcheng = ppDanweimingcheng.trim();
			if(!"".equals(ppDanweimingcheng)) {
				ppDanweimingcheng = "%"+ppDanweimingcheng+"%";
			}

			// 查找该条件下的单位列表
			List<Map<String,Object>> mmDeptList = ddService.findDeptListByCondition(ppDeptId,ppShengfenId,ppDanweimingcheng,ppDanweileixing,ppShezhannianfen);

			ddService.daochuchaxunjieguo(mmDeptList,request,response);


		}catch(Exception e) {
			logger.error("单位附加信息Controller->daochuchaxunjieguo: "+e.getMessage());			
		}
	}


	// 保存单位附加信息
	@RequestMapping("save")
	public JsonResult<?> save(
			@RequestParam("deptid") String ppDeptId,
			@RequestParam("depttype") String ppDepttype,

			@RequestParam("deptyingwenmingcheng") String ppDeptyingwenmingcheng,
			@RequestParam("suoshubumen") String ppSuoshubumen,
			@RequestParam("hangyefenleiid") String ppHangyefenleiid,
			@RequestParam("gongzuozhanleixingid") String ppGongzuozhanleixingid,
			@RequestParam("shezhannianfen") String ppShezhannianfen,

			@RequestParam("danweishangjizhuguanbumen") String ppDanweishangjizhuguanbumen,
			@RequestParam("suozaibumen") String ppSuozaibumen,
			@RequestParam("guanliyuan") String ppGuanliyuan,
			@RequestParam("shengfenid") String ppShengfenid,
			@RequestParam("diquid") String ppDiquid,

			@RequestParam("tongxundizhi") String ppTongxundizhi,
			@RequestParam("dianhuaquhao") String ppDianhuaquhao,
			@RequestParam("dianhua") String ppDianhua,			
			@RequestParam("dianhuafenjihao") String ppDianhuafenjihao,

			@RequestParam("chuanzhenquhao") String ppChuanzhenquhao,
			@RequestParam("chuanzhen") String ppChuanzhen,
			@RequestParam("chuanzhenfenjihao") String ppChuanzhenfenjihao,
			@RequestParam("shoujihaoma") String ppShoujihaoma,
			@RequestParam("dianziyouxiang") String ppDianziyouxiang,

			@RequestParam("shoukuandanweimingcheng") String ppShoukuandanweimingcheng,
			@RequestParam("kaihuhanghangbie") String ppKaihuhanghangbie,
			@RequestParam("kaihuhangmingcheng") String ppKaihuhangmingcheng,
			@RequestParam("yinhangzhanghao") String ppYinhangzhanghao,
			@RequestParam("daehanghao") String ppDaehanghao,

			@RequestParam("zhuangtai") String ppZhuangtai){
		try {

			if("".equals(ppDeptId)) {
				return JsonResult.getErrorResult("单位id不能为空！");
			}

			// 新建
			单位附加信息 mm单位附加信息 = new 单位附加信息();
			mm单位附加信息.set单位id(ppDeptId);

			// 检查数据的合理性
			BooleanMessage mmBooleanMessage = checkInputData(mm单位附加信息,ppDepttype,ppDeptyingwenmingcheng,
					ppSuoshubumen,ppHangyefenleiid,ppGongzuozhanleixingid,ppShezhannianfen,
					ppDanweishangjizhuguanbumen,ppSuozaibumen,ppGuanliyuan,ppShengfenid,ppDiquid,
					ppTongxundizhi,ppDianhuaquhao,ppDianhua,ppDianhuafenjihao,
					ppChuanzhenquhao,ppChuanzhen,ppChuanzhenfenjihao,ppShoujihaoma,ppDianziyouxiang,
					ppShoukuandanweimingcheng,ppKaihuhanghangbie,ppKaihuhangmingcheng,ppYinhangzhanghao,
					ppDaehanghao,ppZhuangtai);

			if(!mmBooleanMessage.isOk()) {
				return JsonResult.getErrorResult(mmBooleanMessage.getMessage().toString());
			}

			// 判断之前是否有数据
			单位附加信息 mmOld单位附加信息 = ddService.findOne(ppDeptId);

			// 有 先删除再添加
			if(mmOld单位附加信息 != null ) {
				return ddService.deleteAndAdd(ppDeptId,mm单位附加信息) ? JsonResult.getSuccessResult("清除并保存成功！") :
					JsonResult.getErrorResult("清除并保存失败！");
			}

			// 无 直接添加
			return ddService.add(mm单位附加信息) ? JsonResult.getSuccessResult("保存成功！") :
				JsonResult.getErrorResult("保存失败！");

		}catch(Exception e) {
			logger.error("单位附加信息Controller->save: "+ e.getMessage());
			return JsonResult.getErrorResult("保存指定单位的附加信息失败");
		}
	}


	// 检查数据
	private BooleanMessage checkInputData(单位附加信息 mm单位附加信息,String ppDepttype, String ppDeptyingwenmingcheng, String ppSuoshubumen,
			String ppHangyefenleiid, String ppGongzuozhanleixingid, String ppShezhannianfen,
			String ppDanweishangjizhuguanbumen, String ppSuozaibumen, String ppGuanliyuan, String ppShengfenid,
			String ppDiquid, String ppTongxundizhi, String ppDianhuaquhao, String ppDianhua,
			String ppDianhuafenjihao, String ppChuanzhenquhao, String ppChuanzhen, String ppChuanzhenfenjihao,
			String ppShoujihaoma, String ppDianziyouxiang,String ppShoukuandanweimingcheng, String ppKaihuhanghangbie,
			String ppKaihuhangmingcheng,String ppYinhangzhanghao, String ppDaehanghao, String ppZhuangtai) {

		ppDeptyingwenmingcheng = ppDeptyingwenmingcheng.trim();
		ppSuoshubumen = ppSuoshubumen.trim();
		ppHangyefenleiid = ppHangyefenleiid.trim();
		ppGongzuozhanleixingid = ppGongzuozhanleixingid.trim();
		ppShezhannianfen = ppShezhannianfen.trim();

		ppDanweishangjizhuguanbumen = ppDanweishangjizhuguanbumen.trim();
		ppSuozaibumen = ppSuozaibumen.trim();
		ppGuanliyuan = ppGuanliyuan.trim();
		ppShengfenid = ppShengfenid.trim();
		ppDiquid = ppDiquid.trim();

		ppTongxundizhi = ppTongxundizhi.trim();
		ppDianhuaquhao = ppDianhuaquhao.trim();
		ppDianhua = ppDianhua.trim();		
		ppDianhuafenjihao = ppDianhuafenjihao.trim();

		ppChuanzhenquhao = ppChuanzhenquhao.trim();
		ppChuanzhen = ppChuanzhen.trim();
		ppChuanzhenfenjihao = ppChuanzhenfenjihao.trim();
		ppShoujihaoma = ppShoujihaoma.trim();
		ppDianziyouxiang = ppDianziyouxiang.trim();

		ppShoukuandanweimingcheng = ppShoukuandanweimingcheng.trim();
		ppKaihuhanghangbie = ppKaihuhanghangbie.trim();
		ppKaihuhangmingcheng = ppKaihuhangmingcheng.trim();
		ppYinhangzhanghao = ppYinhangzhanghao.trim();
		ppDaehanghao = ppDaehanghao.trim();


		// 判空

		// 不为试点省市和非试点省市的都得填写单位英文名称
		if(!(ppDepttype.equals(DeptType.试点省市))&&!(ppDepttype.equals(DeptType.非试点省市))) {
			if ("".equals(ppDeptyingwenmingcheng)) {
				return BooleanMessage.getErrorMessage("单位英文名称不能为空！");
			}
		}

		// 不为试点省市和工作站的都得填写所属部门
		if(!(ppDepttype.equals(DeptType.试点省市)) && !(ppDepttype.equals(DeptType.工作站总站))  && !(ppDepttype.equals(DeptType.非试点省市))
				&& !(ppDepttype.equals(DeptType.工作站企业 )) && !(ppDepttype.equals(DeptType.工作站分站 ))) {
			if ("".equals(ppSuoshubumen)) {
				return BooleanMessage.getErrorMessage("所属部门不能为空！");
			}
		}

		// 不为试点省市和流动站设站单位的下面的内容都需要填写
		if(!(ppDepttype.equals(DeptType.试点省市)) && !(ppDepttype.equals(DeptType.流动站设站单位)) && !(ppDepttype.equals(DeptType.非试点省市)) ) {
			if ("".equals(ppHangyefenleiid)) {
				return BooleanMessage.getErrorMessage("行业分类不能为空！");
			}

			if ("".equals(ppGongzuozhanleixingid)) {
				return BooleanMessage.getErrorMessage("工作站类型不能为空！");
			}

			if ("".equals(ppShezhannianfen)) {
				return BooleanMessage.getErrorMessage("设站年份不能为空！");
			}

			if ("".equals(ppDanweishangjizhuguanbumen)) {
				return BooleanMessage.getErrorMessage("单位上级主管部门不能为空！");
			}

		}

		// 所有单位类型都需要填写下面的内容
		if ("".equals(ppSuozaibumen)) {
			return BooleanMessage.getErrorMessage("博士后工作主管部门不能为空！");
		}

		if ("".equals(ppGuanliyuan)) {
			return BooleanMessage.getErrorMessage("管理员姓名不能为空！");
		}

		if ("".equals(ppDianhuaquhao)) {
			return BooleanMessage.getErrorMessage("电话区号不能为空！");
		}

		if ("".equals(ppDianhua)) {
			return BooleanMessage.getErrorMessage("电话不能为空！");
		}

		if ("".equals(ppChuanzhenquhao)) {
			return BooleanMessage.getErrorMessage("传真区号不能为空！");
		}

		if ("".equals(ppChuanzhen)) {
			return BooleanMessage.getErrorMessage("传真不能为空！");
		}

		if ("".equals(ppShoujihaoma)) {
			return BooleanMessage.getErrorMessage("手机号码不能为空！");
		}

		if ("".equals(ppDianziyouxiang)) {
			return BooleanMessage.getErrorMessage("电子邮件不能为空！");
		}

		if ("".equals(ppShengfenid)) {
			return BooleanMessage.getErrorMessage("通讯地址所在省份不能为空！");
		}

		// 若该省份下有地区，则必须选择
		List<地区> mm地区List = dd地区Service.findByShengfenId(ppShengfenid);
		if(mm地区List.size() > 0) {
			if("".equals(ppDiquid)) {
				return BooleanMessage.getErrorMessage("通讯地址所在地区不能为空！");
			}
		}

		if ("".equals(ppTongxundizhi)) {
			return BooleanMessage.getErrorMessage("详细通讯地址不能为空！");
		}

		// 20201013修改 -- 试点省市无需填写账户信息
		if(!(ppDepttype.equals(DeptType.试点省市)) && !(ppDepttype.equals(DeptType.非试点省市))) {
			if ("".equals(ppShoukuandanweimingcheng)) {
				return BooleanMessage.getErrorMessage("收款单位账户名称不能为空！");
			}

			if ("".equals(ppKaihuhanghangbie)) {
				return BooleanMessage.getErrorMessage("开户行行别不能为空！");
			}

			if ("".equals(ppKaihuhangmingcheng)) {
				return BooleanMessage.getErrorMessage("开户行名称不能为空！");
			}

			if ("".equals(ppYinhangzhanghao)) {
				return BooleanMessage.getErrorMessage("银行账号不能为空！");
			}

			if ("".equals(ppDaehanghao)) {
				return BooleanMessage.getErrorMessage("大额行号不能为空！");
			}
		}


		// 长度检查
		if(StringHandle.getStringByteLength(ppDeptyingwenmingcheng) > 255){
			return BooleanMessage.getErrorMessage("单位英文名称不可超过255字节！");
		}
		if(StringHandle.getStringByteLength(ppSuoshubumen) > 50){
			return BooleanMessage.getErrorMessage("所属部门不可超过50字节！");
		}
		if(StringHandle.getStringByteLength(ppHangyefenleiid) > 50){
			return BooleanMessage.getErrorMessage("行业分类不可超过50字节！");
		}
		if(StringHandle.getStringByteLength(ppGongzuozhanleixingid) > 50){
			return BooleanMessage.getErrorMessage("工作站类型不可超过50字节！");
		}
		if(StringHandle.getStringByteLength(ppDanweishangjizhuguanbumen) > 255){
			return BooleanMessage.getErrorMessage("单位上级主管部门不可超过255字节！");
		}

		if(StringHandle.getStringByteLength(ppSuozaibumen) > 255){
			return BooleanMessage.getErrorMessage("单位博士后工作主管部门不可超过255字节！");
		}
		if(StringHandle.getStringByteLength(ppGuanliyuan) > 50){
			return BooleanMessage.getErrorMessage("管理员姓名不可超过50字节！");
		}	
		if(StringHandle.getStringByteLength(ppDianhuaquhao) > 10){
			return BooleanMessage.getErrorMessage("联系电话区号不可超过10字节！");
		}
		if(StringHandle.getStringByteLength(ppDianhua) > 20){
			return BooleanMessage.getErrorMessage("联系电话不可超过20字节！");
		}
		if(StringHandle.getStringByteLength(ppDianhuafenjihao) > 10){
			return BooleanMessage.getErrorMessage("联系电话分机号不可超过10字节！");
		}

		if(StringHandle.getStringByteLength(ppChuanzhenquhao) > 10){
			return BooleanMessage.getErrorMessage("传真区号不可超过10字节！");
		}
		if(StringHandle.getStringByteLength(ppChuanzhen) > 20){
			return BooleanMessage.getErrorMessage("传真不可超过20字节！");
		}
		if(StringHandle.getStringByteLength(ppChuanzhenfenjihao) > 10){
			return BooleanMessage.getErrorMessage("传真分机号不可超过10字节！");
		}
		if(StringHandle.getStringByteLength(ppShoujihaoma) > 255){
			return BooleanMessage.getErrorMessage("手机号码不可超过255字节！");
		}
		if(StringHandle.getStringByteLength(ppDianziyouxiang) > 255){
			return BooleanMessage.getErrorMessage("电子邮件不可超过255字节！");
		}		

		if(StringHandle.getStringByteLength(ppShengfenid) > 50){
			return BooleanMessage.getErrorMessage("通讯地址所在省份不可超过50字节！");
		}
		if(StringHandle.getStringByteLength(ppDiquid) > 50){
			return BooleanMessage.getErrorMessage("通讯地址所在地区不可超过50字节！");
		}
		if(StringHandle.getStringByteLength(ppTongxundizhi) > 255){
			return BooleanMessage.getErrorMessage("详细通讯地址不可超过255字节！");
		}

		if(StringHandle.getStringByteLength(ppShoukuandanweimingcheng) > 500){
			return BooleanMessage.getErrorMessage("收款单位账户名称不可超过500字节！");
		}

		if(StringHandle.getStringByteLength(ppKaihuhanghangbie) > 50){
			return BooleanMessage.getErrorMessage("开户行行别不可超过50字节！");
		}
		if(StringHandle.getStringByteLength(ppKaihuhangmingcheng) > 500){
			return BooleanMessage.getErrorMessage("开户行名称不可超过500字节！");
		}
		if(StringHandle.getStringByteLength(ppYinhangzhanghao) > 100){
			return BooleanMessage.getErrorMessage("银行账号不可超过100字节！");
		}
		if(StringHandle.getStringByteLength(ppDaehanghao) > 20){
			return BooleanMessage.getErrorMessage("大额行号不可超过20字节！");
		}		


		mm单位附加信息.set单位名称英文(ppDeptyingwenmingcheng);
		mm单位附加信息.set单位所属详细部门id(ppSuoshubumen);
		mm单位附加信息.set行业分类id(ppHangyefenleiid);
		mm单位附加信息.set工作站类型id(ppGongzuozhanleixingid);
		if(!ppShezhannianfen.equals("")) {
			mm单位附加信息.set设站年份(new BigDecimal(ppShezhannianfen));
		}


		mm单位附加信息.set单位上级主管部门(ppDanweishangjizhuguanbumen);
		mm单位附加信息.set博士后工作所在部门(ppSuozaibumen);
		mm单位附加信息.set管理人员姓名(ppGuanliyuan);
		mm单位附加信息.set省份id(ppShengfenid);		
		mm单位附加信息.set地区id(ppDiquid);

		mm单位附加信息.set通讯地址(ppTongxundizhi);
		mm单位附加信息.set电话区号(ppDianhuaquhao);
		mm单位附加信息.set电话(ppDianhua);
		mm单位附加信息.set电话分机号(ppDianhuafenjihao);

		mm单位附加信息.set传真区号(ppChuanzhenquhao);
		mm单位附加信息.set传真(ppChuanzhen);
		mm单位附加信息.set传真分机号(ppChuanzhenfenjihao);
		mm单位附加信息.set手机号码(ppShoujihaoma);
		mm单位附加信息.set电子邮件(ppDianziyouxiang);

		mm单位附加信息.set收款单位名称(ppShoukuandanweimingcheng);
		mm单位附加信息.set开户行行别(ppKaihuhanghangbie);
		mm单位附加信息.set开户行名称(ppKaihuhangmingcheng);
		mm单位附加信息.set银行账号(ppYinhangzhanghao);
		mm单位附加信息.set大额行号(ppDaehanghao);

		mm单位附加信息.set状态(new BigDecimal(ppZhuangtai)); // 暂存为0，提交为1

		return BooleanMessage.getSuccessMessage(mm单位附加信息);
	}

}
